package com.aifast.dict.autoconfigure;

import com.aifast.dict.properties.JfinalActiverecordProperties;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.hikaricp.HikariCpPlugin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author AiFast
 * @since 2022/12/28 11:40
 */
@EnableConfigurationProperties(JfinalActiverecordProperties.class)
@Configuration
public class JfinalActiverecordConfiguration {

    @Autowired
    private JfinalActiverecordProperties properties;
    @Bean
    public ActiveRecordPlugin JfinalActiverecordConfig(){
        HikariCpPlugin hp = new HikariCpPlugin(properties.getUrl(), properties.getUsername(), properties.getPassword());
        ActiveRecordPlugin arp = new ActiveRecordPlugin(hp);
        hp.start();
        arp.start();

        return arp;
    }

}
